package LineCode.剑指Offer.面试思路;

import LineCode.剑指Offer.dto.TreeNode;

import java.util.ArrayList;

import static LineCode.剑指Offer.Utils.TreeNodeUtil.getOneTest1;
import static LineCode.剑指Offer.Utils.TreeNodeUtil.getPreOrderRec;
import static LineCode.剑指Offer.Utils.TreeNodeUtil.printListTreeNode;

/**
 * 操作给定的二叉树，将其变换为源二叉树的镜像。
 */
public class 二叉树的镜像 {

    public static void main(String[] args) {

        TreeNode test1 = getOneTest1();
        printListTreeNode(getPreOrderRec(new ArrayList<TreeNode>(), test1));
        Mirror(test1);
        printListTreeNode(getPreOrderRec(new ArrayList<TreeNode>(), test1));

    }

    public static void Mirror(TreeNode root) {
        if (root != null) {
            Mirror(root.left);
            Mirror(root.right);
            TreeNode node = root.left;
            root.left = root.right;
            root.right = node;
        }
    }
}
